#include "picture.h"

int main(int args,const char *argv[])
{
    if(args != 2)
    {
        printf("请给定一个需要读取图片的目录!\n");
        return 0;
    }
    //初始化存储图片名的结构体    
    struct filetupian *head = csh();
   
    //判断给定argv是否是目录,并读取目录内文件名，找到bmp和jpg格式文件将其存进链表中
    if(dirpdcz(argv[1],head)==0)
    return 0;

    //准备lcd
    struct lcd_info *lcd = calloc(1,sizeof(struct lcd_info));    
    lcd_zhunbei(lcd);
          
    //显示相册封面
    struct tupian_info *fmjpg = calloc(1,sizeof(struct tupian_info));
    tupiansj(jpg,fmjpg,"25.jpg");
    displaytu(jpg,lcd,fmjpg);
    free(fmjpg);
    fmjpg = NULL;  //防止野指针

    while(1)
    {
        //显示相册使用说明
        enum enumread s = fx(); //获取用户滑动屏幕的方向
        if(s == left || s == right)//左滑或者右滑进入
        {
            struct tupian_info *xcsmjpg = calloc(1,sizeof(struct tupian_info)); 
            tupiansj(jpg,xcsmjpg,"20.jpg");
            displaytu(jpg,lcd,xcsmjpg);    
            free(xcsmjpg);
            xcsmjpg = NULL; //防止野指针
        }
    }
    //读完目录之后进入目录
    chdir(argv[1]);

    //相册链表操作
    tupianqh(lcd,head);

    //回到上一级目录
    chdir("..");

    //动态加载图
    struct tupian_info *wjpg = calloc(1,sizeof(struct tupian_info));
    tupiansj(jpg,wjpg,"28.jpg");
    displaytu(jpg,lcd,wjpg);
    free(wjpg);
    wjpg = NULL;

    struct tupian_info *dt = calloc(1,sizeof(struct tupian_info));
    tupiansj(jpg,dt,"jdt.jpg");
    jiazai(lcd,dt);
    free(dt);
    dt = NULL;

    //显示结尾图片
    struct tupian_info *jwjpg = calloc(1,sizeof(struct tupian_info));
    tupiansj(jpg,jwjpg,"27.jpg");
    displaytu(jpg,lcd,jwjpg);
    free(jwjpg);
    jwjpg = NULL;

    //释放lcd相关资源
    lcdsf(lcd);
    free(lcd);
    lcd = NULL;

    return 0;  
}